import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {Switch} from 'antd';

class WrappedSwitch extends Component {
    onChange = checked => {
        this.props.onChange(checked, this.props.name || this.props.id);
    }
    render() {
        const {name, id, onChange, ...rest} = this.props;
        return (
            <Switch onChange={this.onChange} {...rest}/>
        );
    }
}

WrappedSwitch.propTypes = {
    id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    name: PropTypes.string,
    onChange: PropTypes.func
};

export default WrappedSwitch;
